from flask import Blueprint, jsonify
from ..models import Vaccine, AppointmentSlot
from datetime import datetime

vaccine_bp = Blueprint('vaccine', __name__)

@vaccine_bp.route('/list', methods=['GET'])
def get_vaccines():
    vaccines = Vaccine.query.filter_by(status='available').all()
    return jsonify([{
        'id': v.id,
        'name': v.name,
        'manufacturer': v.manufacturer,
        'description': v.description,
        'stock_quantity': v.stock_quantity
    } for v in vaccines])

@vaccine_bp.route('/<int:id>/slots', methods=['GET'])
def get_vaccine_slots(id):
    slots = AppointmentSlot.query.filter_by(vaccine_id=id).all()
    return jsonify([{
        'id': s.id,
        'date': s.date.strftime('%Y-%m-%d'),
        'time_slot': s.time_slot.strftime('%H:%M'),
        'available_quantity': s.available_quantity
    } for s in slots]) 